export default function Pay(
  { nonce_str, order_no, pay_sign, time_stamp },
  data
) {
  return new Promise((resolve, reject) => {
    wx.requestPayment({
      timeStamp: time_stamp.toString(),
      nonceStr: nonce_str,
      package: data.package,
      paySign: pay_sign,
      signType: 'MD5',
      order_no,
      success({ errMsg }) {
        if (errMsg === 'requestPayment:ok') {
          wx.showToast({
            title: '支付成功',
            icon: 'none',
            duration: 2000,
            success() {
              setTimeout(() => {
                resolve(true)
              }, 1000)
            },
          })
        }
      },
      fail({ errMsg }) {
        if (errMsg === 'requestPayment:fail cancel') {
          wx.showToast({
            title: '您取消了支付',
            icon: 'none',
            duration: 2000,
            success() {
              setTimeout(() => {
                resolve(false)
              }, 1000)
            },
          })
        }
      },
    })
  })
}
